import React from "react";
import pubsub from "pubsub-js";
export default function Header() {
  const addItem = (event) => {
    if (event.keyCode === 13 && event.target.value.trim()) {
      pubsub.publish("addItem", event.target.value.trim());
      event.target.value = "";
    }
  };

  return (
    <div className="todo-header">
      <input
        type="text"
        placeholder="请输入你的任务名称，按回车键确认"
        onKeyDown={addItem}
      />
    </div>
  );
}
